<?php
class VideosAdvicesController extends AppController {
    
    public function edit_advice($id) {
        
        $this->VideosAdvice->id = $id;
        if(isset($this->request->data)) {
            if ($this->VideosAdvice->save($this->request->data)){
                $this->Session->setFlash('Votre commentaire a bien été édité.');
                $this->redirect(array('controller'=>'Users', 'action' => 'myVideos'));
            }
            
        }
            
           
        $infos_advice = $this->VideosAdvice->find('first',array('conditions' => array('VideosAdvice.users_videos_id' => $id)));
        $this->set('description',$infos_advice['VideosAdvice']['description']);
            
        $video = $this->User->UsersVideo->getVideos('first', array('conditions' => array(
                                                        'UsersVideo.users_id' => $this->getCurrentUserId(),
                                                        'UsersVideo.id' => $id
        )));
        $this->set('video', $video);
        $this->set('id',$id);
        
        
        
        
        }

    public function askAdvices($id){              
        if (!empty($this->request->data['VideosAdvice'])){            
            $data = $this->request->data;             
            $data['VideosAdvice']['users_videos_id'] = $id;
            debug($data);
            $this->User->UsersVideo->VideosAdvice->save($data);
            if ($this->User->save($data)){
                $this->redirect(array('action' => 'myVideos'));
            }
            else{
                $this->Session->setFlash('Veuillez remplir le formulaire.');
            }
        }       
        
        $video = $this->User->UsersVideo->getVideos('first', array(
            'conditions' => array(
                'UsersVideo.users_id' => $this->getCurrentUserId(),
                'UsersVideo.id' => $id
            )
        ));
        
        $this->set('video', $video);
    }
    
    
}
?>
